package com.wufeng.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wufeng.dto.R;
import com.wufeng.entity.EvaluateRecord;
import com.wufeng.service.EvaluateRecordService;
import com.wufeng.service.EvaluateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/evaluaterecord")
public class EvaluateRecordController {

    @Autowired
    private EvaluateRecordService evaluateRecordService;

    @Autowired
    private EvaluateService evaluateService;

    /**
     * 保存一条测试记录
     *
     * @param evaluateRecord
     * @return
     */
    @PostMapping("/addEvaluateRecord")
    @Transactional
    public R addEvaluateRecord(@RequestBody EvaluateRecord evaluateRecord) {
        boolean isUpdate = evaluateService.addEvaCount(evaluateRecord.getEvaluateid(),evaluateRecord.getUserid());
        boolean isSava = evaluateRecordService.save(evaluateRecord);
        if (!isUpdate||!isSava) {
            R.error("保存失败！");
        }

        return R.ok();
    }

    /**
     * 根据evaluateId获取测试人数
     *
     * @param evaluateId
     * @return
     */
    @GetMapping("/getEvaCountByEvaId")
    public R getEvaCountByEvaId(@RequestParam("evaluateId") Integer evaluateId) {
        Integer count = evaluateRecordService.getEvaCountByEvaId(evaluateId);
        HashMap<String, Object> map = new HashMap<>();
        map.put("count", count);
        return R.ok(map);
    }
}
